
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box" style="position: relative">
        <div class="icon-box">
          <span class="wk wk-my-task icon" />
        </div>
        <span class="text">商机报告</span>
        <j-search-select-tag
          style="width: 150px; margin-left: 15px"
          v-model="personTypeId"
          @change="buTypeChange"
          placeholder="请选择部门"
        >
          <template v-slot>
            <a-select-option v-for="(item, index) in secOptions" :key="index" :value="item.value"
              >{{ item.label }}
            </a-select-option>
          </template>
        </j-search-select-tag>
        <a-range-picker :value="dateInterval" format="YYYY-MM-DD" style="margin-left: 10px" @change="changeDate" />
        <div class="datatypeview">
          <a-tabs v-model="dataTypeKey" @change="dataTypeKeyChange">
            <a-tab-pane key="1" tab="全温区"></a-tab-pane>
            <a-tab-pane key="2" tab="冷冻"></a-tab-pane>
            <a-tab-pane key="3" tab="冷藏"></a-tab-pane>
            <a-tab-pane key="4" tab="恒温"></a-tab-pane>
            <a-tab-pane key="5" tab="常温"></a-tab-pane>
          </a-tabs>
        </div>
      </div>
    </div>

    <div class="table-content">
      <div class="handle-bar">
        <!-- <a-button class="export-btn">导出</a-button> -->
      </div>

      <a-table :scroll="{ y: 300 }" :columns="fieldList" :data-source="tableList" bordered :pagination="false">
        <template slot="warehouseName" slot-scope="text, record">
          <a-tooltip placement="top">
            <template slot="title">
              <span>{{ record.warehouseName }}</span>
            </template>
            <span v-if="userInfo().groupId == '4210'" class="ellipsis" style="width: 100%">{{
              record.warehouseName
            }}</span>
            <span v-else class="ellipsis" style="width: 100%"
              ><a @click="() => businessShow(record)">{{ record.warehouseName }}</a></span
            >
          </a-tooltip>
        </template>
        <span slot="estimatedTotalRate" slot-scope="text, record">
          {{ record.estimatedTotalRate + '%' }}
        </span>
        <span slot="estimatedFreezeRate" slot-scope="text, record">
          {{ record.estimatedFreezeRate + '%' }}
        </span>
        <span slot="estimatedRefrigerateRate" slot-scope="text, record">
          {{ record.estimatedRefrigerateRate + '%' }}
        </span>
        <span slot="estimatedConstantRate" slot-scope="text, record">
          {{ record.estimatedConstantRate + '%' }}
        </span>
        <span slot="estimatedNormalRate" slot-scope="text, record">
          {{ record.estimatedNormalRate + '%' }}
        </span>
      </a-table>
    </div>

    <!-- <div class="analysis">
      <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="analysisActiveMain1" />
          </div>
        </a-col>
      </a-row>

      <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="analysisActiveMain3" /></div
        ></a-col>
      </a-row>
    </div> -->

    <div class="analysis">
      <a-row :span="24">
        <a-col :span="12"
          ><div class="analysis-content">
            <div id="analysisActiveMain5" /></div
        ></a-col>
        <a-col :span="12"
          ><div class="analysis-content">
            <div id="analysisActiveMain6" /></div
        ></a-col>
      </a-row>
    </div>

    <business-list ref="checkModel" @handleShow="handleViewDrawer"></business-list>
    <business-modal ref="modalFormDrawer"></business-modal>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, getAction } from '@/api/manage'
import { mapGetters } from 'vuex'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import BusinessList from './components/BusinessList'
import BusinessModal from '@/views/crm/business/modules/CrmBusinessModal__Style#Drawer'
//获取当前日期
function startDate() {
  var myDate = new Date()
  var nowY = myDate.getFullYear()
  var nowM = myDate.getMonth() + 1
  var nowD = myDate.getDate()
  var enddate = nowY + '-' + (nowM < 10 ? '0' + nowM : nowM) + '-' + (nowD < 10 ? '0' + nowD : nowD) //当前日
  return enddate
}
//获取三十天前日期
function endDate() {
  var myDate = new Date()
  var lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30) //最后一个数字30可改，30天的意思
  var lastY = lw.getFullYear()
  var lastM = lw.getMonth() + 1
  var lastD = lw.getDate()
  var startdate = lastY + '-' + (lastM < 10 ? '0' + lastM : lastM) + '-' + (lastD < 10 ? '0' + lastD : lastD) //三十天之前日期
  return startdate
}
export default {
  /** 客户总量分析 */
  name: 'SummaryReportAll',
  mixins: [JeecgListMixin],
  components: {
    JSearchSelectTag,
    BusinessList,
    BusinessModal,
  },
  data() {
    return {
      loading: false,
      secOptions: [],
      dataTypeKey: '1',
      defaultPersonTypeId: '',
      personTypeId: '',
      dateInterval: [this.sixMonthDate(), this.endDate()],
      fromDate: '',
      thruDate: '',
      chartAnalysis1: null,
      //chartAnalysis2: null,
      chartAnalysis3: null,
      chartAnalysis5: null,
      chartAnalysis6: null,
      analysis1Option: null,
      //analysis2Option: null,
      analysis3Option: null,
      analysis5Option: null,
      analysis6Option: null,

      url: {
        list: '/online/api/',
        selectNowUserBySecurityGroupBu: '/online/api/selectNowUserBySecurityGroupBu',
        getActiveBusinessReport: '/online/api/getActiveBusinessReport',
        businessListByProductCategory: '/online/api/businessListByNewProductCategory',
        exportXlsUrl: '/online/api/export/exportXlsGraphReport',
      },
      postParams: {}, // 筛选参数
      dataIndex: null,
      list: [],
      axisList: [],
      tableList: [],

      // 温区
      buList: [],
      caution_buList: [],
      caution_estimatedTotalRateList: [],
      caution_estimatedTotalRateNoList: [],
      kkwxsrate: [],
      buList1: [],
      caution_buList1: [],
      caution_estimatedFreezeRateList: [],
      caution_estimatedFreezeRateNoList: [],
      kkwxsrate1: [],
      buList2: [],
      caution_buList2: [],
      caution_estimatedRefrigerateRateList: [],
      caution_estimatedRefrigerateRateNoList: [],
      kkwxsrate2: [],
      buList3: [],
      caution_buList3: [],
      caution_estimatedConstantRateList: [],
      caution_estimatedConstantRateNoList: [],
      kkwxsrate3: [],
      buList4: [],
      caution_buList4: [],
      caution_estimatedNormalRateList: [],
      caution_estimatedNormalRateNoList: [],
      kkwxsrate4: [],
    }
  },
  computed: {
    // 列表请求参数
    listPostParams() {
      const params = { ...this.postParams }

      if (this.dataIndex !== undefined && this.dataIndex !== null) {
        const dataItem = this.axisList[this.dataIndex]
        delete params.type
        params.startTime = dataItem.type
        params.endTime = dataItem.type
      }

      return params
    },
    fieldList() {
      let column = []
      if (this.dataTypeKey == '1') {
        column = [
          {
            title: '全温区',
            children: [
              {
                title: '仓库',
                align: 'center',
                dataIndex: 'warehouseName',
                key: 'warehouseName',
                width: 80,
                scopedSlots: { customRender: 'warehouseName' },
              },
              {
                title: '当前空余库位',
                align: 'center',
                dataIndex: 'availableTotal',
                key: 'availableTotal',
                width: 90,
              },
              {
                title: '在售库位',
                align: 'center',
                dataIndex: 'estimatedTotal',
                key: 'estimatedTotal',
                width: 90,
              },
              {
                title: '销售后空余库位',
                align: 'center',
                dataIndex: 'afterFreeTotal',
                key: 'afterFreeTotal',
                width: 90,
              },
              {
                title: '销售库位与空余库位占比',
                align: 'center',
                dataIndex: 'estimatedTotalRate',
                key: 'estimatedTotalRate',
                width: 90,
                scopedSlots: { customRender: 'estimatedTotalRate' },
              },
            ],
          },
        ]
      } else if (this.dataTypeKey == '2') {
        column = [
          {
            title: '冷冻',
            children: [
              {
                title: '仓库',
                align: 'center',
                dataIndex: 'warehouseName',
                key: 'warehouseName',
                width: 80,
                scopedSlots: { customRender: 'warehouseName' },
              },
              {
                title: '当前空余库位',
                align: 'center',
                dataIndex: 'availableFreeze',
                key: 'availableFreeze',
                width: 90,
              },
              {
                title: '在售库位',
                align: 'center',
                dataIndex: 'estimatedFreeze',
                key: 'estimatedFreeze',
                width: 90,
              },
              {
                title: '销售后空余库位',
                align: 'center',
                dataIndex: 'afterFreeFreeze',
                key: 'afterFreeFreeze',
                width: 90,
              },
              {
                title: '销售库位与空余库位占比',
                align: 'center',
                dataIndex: 'estimatedFreezeRate',
                key: 'estimatedFreezeRate',
                width: 90,
                scopedSlots: { customRender: 'estimatedFreezeRate' },
              },
            ],
          },
        ]
      } else if (this.dataTypeKey == '3') {
        column = [
          {
            title: '冷藏',
            children: [
              {
                title: '仓库',
                align: 'center',
                dataIndex: 'warehouseName',
                key: 'warehouseName',
                width: 80,
                scopedSlots: { customRender: 'warehouseName' },
              },
              {
                title: '当前空余库位',
                align: 'center',
                dataIndex: 'availableRefrigerate',
                key: 'availableRefrigerate',
                width: 90,
              },
              {
                title: '在售库位',
                align: 'center',
                dataIndex: 'estimatedRefrigerate',
                key: 'estimatedRefrigerate',
                width: 90,
              },
              {
                title: '销售后空余库位',
                align: 'center',
                dataIndex: 'afterFreeRefrigerate',
                key: 'afterFreeRefrigerate',
                width: 90,
              },
              {
                title: '销售库位与空余库位占比',
                align: 'center',
                dataIndex: 'estimatedRefrigerateRate',
                key: 'estimatedRefrigerateRate',
                width: 90,
                scopedSlots: { customRender: 'estimatedRefrigerateRate' },
              },
            ],
          },
        ]
      } else if (this.dataTypeKey == '4') {
        column = [
          {
            title: '恒温',
            children: [
              {
                title: '仓库',
                align: 'center',
                dataIndex: 'warehouseName',
                key: 'warehouseName',
                width: 80,
                scopedSlots: { customRender: 'warehouseName' },
              },
              {
                title: '当前空余库位',
                align: 'center',
                dataIndex: 'availableConstant',
                key: 'availableConstant',
                width: 90,
              },
              {
                title: '在售库位',
                align: 'center',
                dataIndex: 'estimatedConstant',
                key: 'estimatedConstant',
                width: 90,
              },
              {
                title: '销售后空余库位',
                align: 'center',
                dataIndex: 'afterFreeConstant',
                key: 'afterFreeConstant',
                width: 90,
              },
              {
                title: '销售库位与空余库位占比',
                align: 'center',
                dataIndex: 'estimatedConstantRate',
                key: 'estimatedConstantRate',
                width: 90,
                scopedSlots: { customRender: 'estimatedConstantRate' },
              },
            ],
          },
        ]
      } else {
        column = [
          {
            title: '常温',
            children: [
              {
                title: '仓库',
                align: 'center',
                dataIndex: 'warehouseName',
                key: 'warehouseName',
                width: 80,
                scopedSlots: { customRender: 'warehouseName' },
              },
              {
                title: '当前空余库位',
                align: 'center',
                dataIndex: 'availableNormal',
                key: 'availableNormal',
                width: 90,
              },
              {
                title: '在售库位',
                align: 'center',
                dataIndex: 'estimatedNormal',
                key: 'estimatedNormal',
                width: 90,
              },
              {
                title: '销售后空余库位',
                align: 'center',
                dataIndex: 'afterFreeNormal',
                key: 'afterFreeNormal',
                width: 90,
              },
              {
                title: '销售库位与空余库位占比',
                align: 'center',
                dataIndex: 'estimatedNormalRate',
                key: 'estimatedNormalRate',
                width: 90,
                scopedSlots: { customRender: 'estimatedNormalRate' },
              },
            ],
          },
        ]
      }
      return column
    },
  },
  mounted() {
    this.selectSec()
  },
  methods: {
    ...mapGetters(['userInfo']),
    /**
     * 搜索点击
     */
    searchClick(params) {
      this.postParams = params
      this.getDataList()
      this.getRecordList()
    },
    /**
     * 图表数据   待完善
     */
    getDataList() {
      // this.chartAnalysis1.setOption(this.analysis1Option, true)
      // this.chartAnalysis3.setOption(this.analysis3Option, true)
      this.chartAnalysis5.setOption(this.analysis5Option, true)
      this.chartAnalysis6.setOption(this.analysis6Option, true)
    },
    /**
     * 获取相关列表
     */
    getRecordList(dataIndex) {
      this.dataIndex = dataIndex
      this.list = []
      this.loading = true
      biCustomerTotalListAPI(this.listPostParams)
        .then((res) => {
          this.loading = false
          const data = res.result || {}
          this.list = data.list || []
          this.getSummariesData(data.total)
        })
        .catch(() => {
          this.loading = false
        })
    },

    /** 图表 */
    async initAxis() {
      this.dataTypeKey = '1'
      // this.chartAnalysis1 = this.echarts.init(document.getElementById('analysisActiveMain1'))
      // this.chartAnalysis3 = this.echarts.init(document.getElementById('analysisActiveMain3'))
      this.chartAnalysis5 = this.echarts.init(document.getElementById('analysisActiveMain5'))
      this.chartAnalysis6 = this.echarts.init(document.getElementById('analysisActiveMain6'))

      this.analysis1Option = {
        title: {
          text: '销售库位与空库位占比',
          left: 'center',
        },
        dataZoom: [
          {
            // 控制图表左右滑动
            width: '15',
            type: 'slider',
            show: false, //flase直接隐藏图形
            xAxisIndex: [0],
            left: 33, //滚动条靠左侧的百分比
            bottom: 40,
            height: 20, //组件高度
            start: 0, //滚动条的起始位置
            showDataShadow: false, //是否显示数据阴影
            showDetail: false, //是否显示想洗数值信息
            end: 100, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
          {
            type: 'inside',
            show: true,
            xAxisIndex: [0],
            start: 0, //滚动条的起始位置
            end: 0.25, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
        ],
        legend: {
          right: '300',
          data: ['在售中', '未达标'],
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
          },
          formatter: function (params, ticket, callback) {
            var htmlStr = ''
            for (var i = 0; i < params.length; i++) {
              var param = params[i]
              var xName = param.name
              var seriesName = param.seriesName
              var value = param.value ? param.value + '%' : '-'
              var color = param.color
              if (i === 0) {
                htmlStr += xName + '<br/>'
              }
              htmlStr += '<div>'
              htmlStr +=
                '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' +
                color +
                ';"></span>'
              htmlStr += seriesName + '：' + value
              htmlStr += '<div/>'
            }
            return htmlStr
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            axisLabel: {
              interval: 0,
              rotate: 30,
            },
            type: 'category',
            data: [],
          },
        ],
        yAxis: [
          {
            type: 'value',
            axisLabel: {
              formatter: '{value}%',
            },
          },
        ],
        series: [
          {
            name: '在售中',
            type: 'bar',
            color: '#0000FF',
            stack: '全温区',
            barWidth: '20%',
            label: {
              show: true,
              position: 'top',
              offset: [0, 20],
              formatter: (params) => {
                if (params.value != 0) {
                  return params.value + '%'
                } else {
                  return ''
                }
              },
            },
            emphasis: {
              focus: 'series',
            },
            data: [],
          },
          {
            name: '未达标',
            type: 'bar',
            color: '#fd4d4d',
            stack: '全温区',
            barWidth: '20%',
            label: {
              show: true,
              position: 'top',
              offset: [0, 20],
              formatter: (params) => {
                if (params.value != 0) {
                  return params.value + '%'
                } else {
                  return ''
                }
              },
            },
            data: [],
            emphasis: {
              focus: 'series',
            },
            itemStyle: {
              normal: {
                color: function (params) {
                  return '#fd4d4d'
                },
              },
            },
          },
        ],
      }
      this.analysis3Option = {
        title: {
          text: '销售后空余库位',
          left: 'center',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        dataZoom: [
          {
            // 控制图表左右滑动
            width: '15',
            type: 'slider',
            show: false, //flase直接隐藏图形
            xAxisIndex: [0],
            left: 33, //滚动条靠左侧的百分比
            bottom: 40,
            height: 20, //组件高度
            start: 0, //滚动条的起始位置
            showDataShadow: false, //是否显示数据阴影
            showDetail: false, //是否显示想洗数值信息
            end: 100, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
          {
            type: 'inside',
            show: true,
            xAxisIndex: [0],
            start: 0, //滚动条的起始位置
            end: 0.25, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
        ],
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            axisLabel: {
              interval: 0,
              rotate: 30,
            },
            type: 'category',
            data: [],
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
        series: [
          {
            type: 'bar',
            color: '#0080FF',
            barWidth: '20%',
            label: {
              show: true,
              position: 'top',
              offset: [0, 20],
            },
            emphasis: {
              focus: 'series',
            },
            data: [],
          },
        ],
      }
      this.analysis5Option = {
        title: {
          text: '客户图（个数）',
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            name: '产品品类',
            type: 'pie',
            radius: '50%',
            data: [],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)',
              },
            },
          },
        ],
      }
      this.analysis6Option = {
        title: {
          text: '商机图（金额）',
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            name: '产品品类',
            type: 'pie',
            radius: '50%',
            data: [
              {
                value: 0,
                name: '商超',
              },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)',
              },
            },
          },
        ],
      }

      const param = {}
      param.createTime_fld0_value = this.dateInterval[0]
      param.createTime_fld1_value = this.dateInterval[1]
      param.personTypeId = this.personTypeId
      ;(async () => {})()

      const res2 = await getAction(this.url.businessListByProductCategory, { personTypeId: this.personTypeId })
      let businessProduct = []
      res2.result.workMap.businessListByProductCategory.forEach((e) => {
        businessProduct.push({
          value: e.businessNum,
          name: e.productCategoryName,
        })
      })
      this.analysis6Option.series[0].data = businessProduct

      const res = await getAction(this.url.getActiveBusinessReport, param)
      this.buList = []
      this.caution_buList = []
      this.caution_estimatedTotalRateList = []
      this.caution_estimatedTotalRateNoList = []
      this.kkwxsrate = []

      this.buList1 = []
      this.caution_buList1 = []
      this.caution_estimatedFreezeRateList = []
      this.caution_estimatedFreezeRateNoList = []
      this.kkwxsrate1 = []

      this.buList2 = []
      this.caution_buList2 = []
      this.caution_estimatedRefrigerateRateList = []
      this.caution_estimatedRefrigerateRateNoList = []
      this.kkwxsrate2 = []

      this.buList3 = []
      this.caution_buList3 = []
      this.caution_estimatedConstantRateList = []
      this.caution_estimatedConstantRateNoList = []
      this.kkwxsrate3 = []

      this.buList4 = []
      this.caution_buList4 = []
      this.caution_estimatedNormalRateList = []
      this.caution_estimatedNormalRateNoList = []
      this.kkwxsrate4 = []

      let customerProduct = []

      let list = res.result.workMap.customerListByProductCategory
      list.forEach((e) => {
        customerProduct.push({
          value: e.customerNum,
          name: e.productCategoryName,
        })
      })
      this.analysis5Option.series[0].data = customerProduct
      res.result.workMap.salesDataListByWarehouse.forEach((element) => {
        element.afterFreeTotal = element.availableTotal - element.estimatedTotal
        element.afterFreeFreeze = element.availableFreeze - element.estimatedFreeze
        element.afterFreeRefrigerate = element.availableRefrigerate - element.estimatedRefrigerate
        element.afterFreeConstant = element.availableConstant - element.estimatedConstant
        element.afterFreeNormal = element.availableNormal - element.estimatedNormal
      })

      // 全温区 start
      let afterTotalRateList = []
      let afterTotalkkwxsrateList = []
      afterTotalRateList = res.result.workMap.cautionSalesDataListByWarehouse
        .slice(0)
        .sort(this.mySort('estimatedTotalRate'))

      afterTotalkkwxsrateList = res.result.workMap.cautionSalesDataListByWarehouse.slice(0)
      afterTotalkkwxsrateList.forEach((e) => {
        e.showAfterSales = e.availableTotal - e.estimatedTotal
      })
      afterTotalkkwxsrateList.sort(this.mySort2('showAfterSales'))
      afterTotalRateList.forEach((e) => {
        this.caution_buList.push(e.warehouseName)
        if (e.estimatedTotalRate > 200) {
          e.showestimatedTotalRate = 200
        } else {
          e.showestimatedTotalRate = e.estimatedTotalRate
        }
        if (e.estimatedTotalRateNo < 0) {
          e.showestimatedTotalRateNo = 0
        } else {
          e.showestimatedTotalRateNo = e.estimatedTotalRateNo
        }
        this.caution_estimatedTotalRateList.push(e.showestimatedTotalRate)
        this.caution_estimatedTotalRateNoList.push(e.showestimatedTotalRateNo)
      })
      afterTotalkkwxsrateList.forEach((e2) => {
        this.buList.push(e2.warehouseName)
        this.kkwxsrate.push(e2.showAfterSales)
      })
      // end

      // 冷冻 start
      let afterFreezeRateList = []
      let afterFreezekkwxsrateList = []
      afterFreezeRateList = res.result.workMap.salesDataListByWarehouse
        .slice(0)
        .sort(this.mySort('estimatedFreezeRate'))

      afterFreezekkwxsrateList = res.result.workMap.salesDataListByWarehouse.slice(0)
      afterFreezekkwxsrateList.forEach((e) => {
        e.showAfterSales = e.availableFreeze - e.estimatedFreeze
      })
      afterFreezekkwxsrateList.sort(this.mySort2('showAfterSales'))
      afterFreezeRateList.forEach((e) => {
        this.caution_buList1.push(e.warehouseName)
        if (e.estimatedFreezeRate > 200) {
          e.showestimatedFreezeRate = 200
        } else {
          e.showestimatedFreezeRate = e.estimatedFreezeRate
        }
        if (e.estimatedFreezeRateNo < 0) {
          e.showestimatedFreezeRateNo = 0
        } else {
          e.showestimatedFreezeRateNo = e.estimatedFreezeRateNo
        }
        this.caution_estimatedFreezeRateList.push(e.showestimatedFreezeRate)
        this.caution_estimatedFreezeRateNoList.push(e.showestimatedFreezeRateNo)
      })
      afterFreezekkwxsrateList.forEach((e2) => {
        this.buList1.push(e2.warehouseName)
        this.kkwxsrate1.push(e2.showAfterSales)
      })
      // end

      // 冷藏 start
      let afterRefrigerateRateList = []
      let afterRefrigeratekkwxsrateList = []
      afterRefrigerateRateList = res.result.workMap.salesDataListByWarehouse
        .slice(0)
        .sort(this.mySort('estimatedRefrigerateRate'))

      afterRefrigeratekkwxsrateList = res.result.workMap.salesDataListByWarehouse.slice(0)
      afterRefrigeratekkwxsrateList.forEach((e) => {
        e.showAfterSales = e.availableRefrigerate - e.estimatedRefrigerate
      })
      afterRefrigeratekkwxsrateList.sort(this.mySort2('showAfterSales'))
      afterRefrigerateRateList.forEach((e) => {
        this.caution_buList2.push(e.warehouseName)
        if (e.estimatedRefrigerateRate > 200) {
          e.showestimatedRefrigerateRate = 200
        } else {
          e.showestimatedRefrigerateRate = e.estimatedRefrigerateRate
        }
        if (e.estimatedRefrigerateRateNo < 0) {
          e.showestimatedRefrigerateRateNo = 0
        } else {
          e.showestimatedRefrigerateRateNo = e.estimatedRefrigerateRateNo
        }
        this.caution_estimatedRefrigerateRateList.push(e.showestimatedRefrigerateRate)
        this.caution_estimatedRefrigerateRateNoList.push(e.showestimatedRefrigerateRateNo)
      })
      afterRefrigeratekkwxsrateList.forEach((e2) => {
        this.buList2.push(e2.warehouseName)
        this.kkwxsrate2.push(e2.showAfterSales)
      })
      // end

      // 恒温 start
      let afterConstantRateList = []
      let afterConstantkkwxsrateList = []
      afterConstantRateList = res.result.workMap.salesDataListByWarehouse
        .slice(0)
        .sort(this.mySort('estimatedConstantRate'))

      afterConstantkkwxsrateList = res.result.workMap.salesDataListByWarehouse.slice(0)
      afterConstantkkwxsrateList.forEach((e) => {
        e.showAfterSales = e.availableConstant - e.estimatedConstant
      })
      afterConstantkkwxsrateList.sort(this.mySort2('showAfterSales'))
      afterConstantRateList.forEach((e) => {
        this.caution_buList3.push(e.warehouseName)
        if (e.estimatedConstantRate > 200) {
          e.showestimatedConstantRate = 200
        } else {
          e.showestimatedConstantRate = e.estimatedConstantRate
        }
        if (e.estimatedConstantRateNo < 0) {
          e.showestimatedConstantRateNo = 0
        } else {
          e.showestimatedConstantRateNo = e.estimatedConstantRateNo
        }
        this.caution_estimatedConstantRateList.push(e.showestimatedConstantRate)
        this.caution_estimatedConstantRateNoList.push(e.showestimatedConstantRateNo)
      })
      afterConstantkkwxsrateList.forEach((e2) => {
        this.buList3.push(e2.warehouseName)
        this.kkwxsrate3.push(e2.showAfterSales)
      })
      // end

      // 常温 start
      let afterNormalRateList = []
      let afterNormalkkwxsrateList = []
      afterNormalRateList = res.result.workMap.salesDataListByWarehouse
        .slice(0)
        .sort(this.mySort('estimatedNormalRate'))

      afterNormalkkwxsrateList = res.result.workMap.salesDataListByWarehouse.slice(0)
      afterNormalkkwxsrateList.forEach((e) => {
        e.showAfterSales = e.availableNormal - e.estimatedNormal
      })
      afterNormalkkwxsrateList.sort(this.mySort2('showAfterSales'))
      afterNormalRateList.forEach((e) => {
        this.caution_buList4.push(e.warehouseName)
        if (e.estimatedNormalRate > 200) {
          e.showestimatedNormalRate = 200
        } else {
          e.showestimatedNormalRate = e.estimatedNormalRate
        }
        if (e.estimatedNormalRateNo < 0) {
          e.showestimatedNormalRateNo = 0
        } else {
          e.showestimatedNormalRateNo = e.estimatedNormalRateNo
        }
        this.caution_estimatedNormalRateList.push(e.showestimatedNormalRate)
        this.caution_estimatedNormalRateNoList.push(e.showestimatedNormalRateNo)
      })
      afterNormalkkwxsrateList.forEach((e2) => {
        this.buList4.push(e2.warehouseName)
        this.kkwxsrate4.push(e2.showAfterSales)
      })
      // end

      this.analysis1Option.xAxis[0].data = this.caution_buList
      this.analysis1Option.series[0].data = this.caution_estimatedTotalRateList
      this.analysis1Option.series[1].data = this.caution_estimatedTotalRateNoList
      this.analysis3Option.xAxis[0].data = this.buList
      this.analysis3Option.series[0].data = this.kkwxsrate

      let salesDataListByWarehouseHz = []
      salesDataListByWarehouseHz = res.result.workMap.salesDataListByWarehouse
      salesDataListByWarehouseHz.push(res.result.workMap.salesDataListByWarehouseHuizong)
      this.tableList = salesDataListByWarehouseHz
      this.fromDate = res.result.workMap.fromDate
      this.thruDate = res.result.workMap.thruDate

      this.$nextTick(() => {
        this.getDataList()
      })
    },
    dataTypeKeyChange(e) {
      // if (e == '2') {
      //   this.analysis1Option.xAxis[0].data = this.caution_buList1
      //   this.analysis1Option.series[0].data = this.caution_estimatedFreezeRateList
      //   this.analysis1Option.series[1].data = this.caution_estimatedFreezeRateNoList
      //   this.analysis3Option.xAxis[0].data = this.buList1
      //   this.analysis3Option.series[0].data = this.kkwxsrate1
      // } else if (e == '3') {
      //   this.analysis1Option.xAxis[0].data = this.caution_buList2
      //   this.analysis1Option.series[0].data = this.caution_estimatedRefrigerateRateList
      //   this.analysis1Option.series[1].data = this.caution_estimatedRefrigerateRateNoList
      //   this.analysis3Option.xAxis[0].data = this.buList2
      //   this.analysis3Option.series[0].data = this.kkwxsrate2
      // } else if (e == '4') {
      //   this.analysis1Option.xAxis[0].data = this.caution_buList3
      //   this.analysis1Option.series[0].data = this.caution_estimatedConstantRateList
      //   this.analysis1Option.series[1].data = this.caution_estimatedConstantRateNoList
      //   this.analysis3Option.xAxis[0].data = this.buList3
      //   this.analysis3Option.series[0].data = this.kkwxsrate3
      // } else if (e == '5') {
      //   this.analysis1Option.xAxis[0].data = this.caution_buList4
      //   this.analysis1Option.series[0].data = this.caution_estimatedNormalRateList
      //   this.analysis1Option.series[1].data = this.caution_estimatedNormalRateNoList
      //   this.analysis3Option.xAxis[0].data = this.buList4
      //   this.analysis3Option.series[0].data = this.kkwxsrate4
      // } else {
      //   this.analysis1Option.xAxis[0].data = this.caution_buList
      //   this.analysis1Option.series[0].data = this.caution_estimatedTotalRateList
      //   this.analysis1Option.series[1].data = this.caution_estimatedTotalRateNoList
      //   this.analysis3Option.xAxis[0].data = this.buList
      //   this.analysis3Option.series[0].data = this.kkwxsrate
      // }
      // this.$nextTick(() => {
      //   this.chartAnalysis1.setOption(this.analysis1Option, true)
      //   this.chartAnalysis3.setOption(this.analysis3Option, true)
      // })
    },

    selectSec() {
      const param = {}
      getAction(this.url.selectNowUserBySecurityGroupBu, param).then((res) => {
        if (res.success) {
          this.secOptions = res.result.list || []
          if (res.result.list) {
            this.personTypeId = res.result.list[0].value
            this.defaultPersonTypeId = res.result.list[0].value
          }
          this.$nextTick(() => {
            this.initAxis()
          })
        }
      })
    },
    changeDate(date, dateString) {
      if (dateString[0] == '' && dateString[1] == '') {
        this.dateInterval = [this.sixMonthDate(), this.endDate()]
      } else {
        this.dateInterval = dateString
      }

      this.initAxis()
    },
    buTypeChange(e) {
      if (e === undefined) {
        this.personTypeId = this.defaultPersonTypeId
      }
      this.initAxis()
    },

    //获取当前日期
    endDate() {
      var myDate = new Date()
      var nowY = myDate.getFullYear()
      var nowM = myDate.getMonth() + 1
      var nowD = myDate.getDate()
      var enddate = nowY + '-' + (nowM < 10 ? '0' + nowM : nowM) + '-' + (nowD < 10 ? '0' + nowD : nowD) //当前日
      return enddate
    },

    //获取三十天前日期
    startDate() {
      var myDate = new Date()
      var lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30) //最后一个数字30可改，30天的意思
      var lastY = lw.getFullYear()
      var lastM = lw.getMonth() + 1
      var lastD = lw.getDate()
      var startdate = lastY + '-' + (lastM < 10 ? '0' + lastM : lastM) + '-' + (lastD < 10 ? '0' + lastD : lastD) //三十天之前日期
      return startdate
    },

    startDate1() {
      var myDate = new Date()
      var lw = new Date(myDate - 1000 * 60 * 60 * 24 * 365) //最后一个数字30可改，30天的意思
      var lastY = lw.getFullYear()
      var lastM = lw.getMonth() + 1
      var lastD = lw.getDate()
      var startdate = lastY + '-' + (lastM < 10 ? '0' + lastM : lastM) + '-' + (lastD < 10 ? '0' + lastD : lastD) //三十天之前日期
      return startdate
    },
    sixMonthDate() {
      let date = new Date()
      let Y = date.getFullYear()
      let M = date.getMonth() + 1
      let lastY
      let lastM
      if (M > 6) {
        lastY = Y
        lastM = M - 6
      } else {
        lastY = Y - 1
        lastM = M + 6
      }
      if (M < 10) {
        M = '0' + M
      }
      if (lastM < 10) {
        lastM = '0' + lastM
      }
      let monthB = lastY + '-' + lastM + '-01'
      return monthB
    },

    mySort(property) {
      return function (a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value1 - value2
      }
    },
    mySort2(property) {
      return function (a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value2 - value1
      }
    },
    // 打开商机列表
    businessShow(record) {
      let warehouseId = ''
      if (record.warehouseId == '_NA_') {
        this.tableList.forEach((item) => {
          if (item.warehouseId && item.warehouseId !== '_NA_') {
            warehouseId = warehouseId + ',' + item.warehouseId
          }
        })
        record.warehouseId = warehouseId
      }
      let param = {}
      param.createTime_fld0_value = this.dateInterval[0]
      param.createTime_fld1_value = this.dateInterval[1]
      param.personTypeId = this.personTypeId
      this.$refs.checkModel.show(record, param)
    },

    /**
     * 导出点击
     */
    exportClick() {
      this.requestExportInfo(biCustomerTotalListExportAPI, this.listPostParams)
    },
  },
}
</script>


<style lang="less" scoped>
/deep/ .ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  padding: 10px 4px;
}
/deep/ .ant-tabs {
  vertical-align: middle;
}
/deep/ .ant-tabs-bar {
  margin: 0;
}
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #168a40;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }

  .datatypeview {
    position: absolute;
    display: inline-block;
    bottom: 1px;
    right: 15px;
  }
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}
.analysis {
  margin-top: 10px;
  .analysis-content {
    padding: 8px 10px;
    .tips {
      padding-left: 8%;
      font-size: 12px;
      div {
        margin-bottom: 8px;
      }
    }
    #analysisActiveMain1 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
    #analysisActiveMain2 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
    #analysisActiveMain3 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
    #analysisActiveMain5 {
      margin: 0 auto;
      width: 95%;
      height: 500px;
    }
    #analysisActiveMain6 {
      margin: 0 auto;
      width: 95%;
      height: 500px;
    }
  }
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
  .axismain,
  #summaryAll1 {
    margin: 0 auto;
    width: 100%;
    height: 400px;
  }
}

.table-content {
  padding: 0 30px 20px 30px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
/deep/ .ant-table-wrapper {
  border: 1px solid #ebeef5;
}
/deep/ .ant-table-placeholder {
  display: none;
}

/deep/ .ant-modal-mask {
  z-index: 89 !important;
}
/deep/ .ant-modal-wrap {
  z-index: 89 !important;
}
</style>

